Skip to content

Fix #7458: Refine typevar interpolation #7562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2019
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Nov 16, 2019

If there are several type variables to instantiate in an interpolation call,
instantiate first those type variables that do not tighten the constraint for
other instantiatable type variables.

The following code from i7458.scala requires this new scheme to compile.

type Tr[+V1, +O1 <: V1]
def [V2, O2 <: V2](tr: Tr[V2, O2]) sl: Tr[V2, O2] = ???
def as[V3, O3 <: V3](tr: Tr[V3, O3]) : Tr[V3, O3] = tr.sl

Interestingly, adding () to the parameter list of sl makes
the problem disappear even without the fix. The reason is that in
this case interpolation is suspended to a later point since expressions of
method type are not interpolated.

If there are several type variables to instantiate in an interpolation call,
instantiate first those type variables that do not tighten the constraint for
other instantiatable type variables.

The following code from i7458.scala requires this new scheme to compile.
```
type Tr[+V1, +O1 <: V1]
def [V2, O2 <: V2](tr: Tr[V2, O2]) sl: Tr[V2, O2] = ???
def as[V3, O3 <: V3](tr: Tr[V3, O3]) : Tr[V3, O3] = tr.sl
```
Interestingly, adding `()` to the parameter list of `sl` makes
the problem disappear even without the fix. The reason is that in
this case interpolation is suspended to a later point since expressions of
method type are not interpolated.
@odersky odersky marked this pull request as ready for review November 17, 2019 11:11
Comment on lines 479 to 480
if fromBelow then constraint.isLess(following.origin, tvar.origin)
else constraint.isLess(following.origin, tvar.origin)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are the same, I assume one is supposed to have its parameters flipped ? (Incidentally this is why I like to always put a new line before each branch of an if/else, this makes this sort of things easier to spot :)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad you spotted this!

@smarter smarter merged commit 3d42550 into scala:master Nov 18, 2019
@smarter smarter deleted the fix-#7458 branch November 18, 2019 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants